//
//  ProductCenterWareTableViewCell.m
//  WholesalerApp
//
//  Created by macox on 16/11/2.
//  Copyright © 2016年 macox. All rights reserved.
//

#import "ProductCenterWareTableViewCell.h"

@implementation ProductCenterWareTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    _GroundingBtn.layer.borderColor = [[UIColor orangeColor] CGColor];
    _GroundingBtn.backgroundColor = [UIColor whiteColor];
    _GroundingBtn.layer.borderWidth = 0.5f;
    _GroundingBtn.layer.masksToBounds = YES;
    
    
    _DelectBtn.layer.borderColor = [[UIColor orangeColor] CGColor];
    _DelectBtn.backgroundColor = [UIColor whiteColor];
    _DelectBtn.layer.borderWidth = 0.5f;
    _DelectBtn.layer.masksToBounds = YES;
    
    
    
    _EditBtn.layer.borderColor = [[UIColor orangeColor] CGColor];
    _EditBtn.backgroundColor = [UIColor whiteColor];
    _EditBtn.layer.borderWidth = 0.5f;
    _EditBtn.layer.masksToBounds = YES;
    
    // Initialization code
}
- (void)setModel:(ProductModel *)model{
    NSLog(@"%@",model);
//    NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,model.ImagePath];
//    NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
//    _CommodityWImage.image = [UIImage imageWithData:data];
    
    dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
        NSString *imageStr = [NSString stringWithFormat:@"%@%@",ReleaseORDebug,model.ImagePath];
        NSData *data = [NSData dataWithContentsOfURL:[NSURL URLWithString:imageStr]];
        dispatch_async(dispatch_get_main_queue(), ^{
            _CommodityWImage.image = [UIImage imageWithData:data];
        });
    });
    _CommodityWTitle.text = model.ProductName;
    /**价格
     */
    NSString *stringPrice = [NSString stringWithFormat:@"%.2f元",model.MarketPrice];
    _CommodityWPrice.text = stringPrice;
    _MaeketPriceString  = [NSString stringWithFormat:@"%.2f",model.MarketPrice];
    _StockString = model.Stock;
    
    if ([[NNSingleton sharedSingleton].btnState isEqualToString:@"1"]) {
        [_GroundingBtn setTitle:@"下架" forState:UIControlStateNormal];
        _EditBtn.backgroundColor = [UIColor whiteColor];
        [_EditBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _EditBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
        _EditBtn.backgroundColor = [UIColor whiteColor];
        _EditBtn.layer.borderWidth = 0.5f;
        _EditBtn.layer.masksToBounds = YES;
        _EditBtn.userInteractionEnabled = NO;
    }else if ([[NNSingleton sharedSingleton].btnState isEqualToString:@"3"]) {
        [_GroundingBtn setTitle:@"上架" forState:UIControlStateNormal];
         _EditBtn.userInteractionEnabled = YES;
        
    }else if ([[NNSingleton sharedSingleton].btnState isEqualToString:@"2"]) {
        _EditBtn.backgroundColor = [UIColor whiteColor];
        [_EditBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _EditBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
        _EditBtn.backgroundColor = [UIColor whiteColor];
        _EditBtn.layer.borderWidth = 0.5f;
        _EditBtn.layer.masksToBounds = YES;
         _EditBtn.userInteractionEnabled = NO;
        
        
        _GroundingBtn.backgroundColor = [UIColor whiteColor];
        [_GroundingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _GroundingBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
        _GroundingBtn.backgroundColor = [UIColor whiteColor];
        _GroundingBtn.layer.borderWidth = 0.5f;
        _GroundingBtn.layer.masksToBounds = YES;
        _GroundingBtn.userInteractionEnabled = NO;
        
    }else if ([[NNSingleton sharedSingleton].btnState isEqualToString:@"4"]) {
        
        _EditBtn.backgroundColor = [UIColor whiteColor];
        [_EditBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _EditBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
        _EditBtn.backgroundColor = [UIColor whiteColor];
        _EditBtn.layer.borderWidth = 0.5f;
        _EditBtn.layer.masksToBounds = YES;
         _EditBtn.userInteractionEnabled = NO;
        
        
        
        _GroundingBtn.backgroundColor = [UIColor whiteColor];
        [_GroundingBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        _GroundingBtn.layer.borderColor = [[UIColor whiteColor] CGColor];
        _GroundingBtn.backgroundColor = [UIColor whiteColor];
        _GroundingBtn.layer.borderWidth = 0.5f;
        _GroundingBtn.layer.masksToBounds = YES;
       _GroundingBtn.userInteractionEnabled = NO;
      
    }
    _Id = model.Id;
}
- (IBAction)EditBtnAction:(UIButton *)sender {
    [self.delegate trunEditGroundingVC:[NSString stringWithFormat:@"%d",_Id] :_MaeketPriceString :_StockString];
}
- (IBAction)GroudingBtnAction:(UIButton *)sender {
    [self.delegate GroundingVC:[NSString stringWithFormat:@"%d",_Id]];
}
- (IBAction)DeleteBtnAction:(UIButton *)sender {
    [self.delegate DeleteVC:[NSString stringWithFormat:@"%d",_Id]];
}
- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
